home *** CD-ROM | disk | FTP | other *** search
/ The Programmer Disk / The Programmer Disk (Microforum).iso / xpro / qb2 / pro16 / tabman.bas < prev    next >
BASIC Source File  |  1992-01-02  |  4KB  |  121 lines

  1. ' TabMan.Bas - Tab handling functions that handle both
  2. '              fixed-interval and irregular-interval tab stops.
  3. '              The fixed-interval mode computes tab stops on
  4. '              the fly, while the irregular-interval mode
  5. '              uses the Bit Array package routines to allow you
  6. '              to specify multiple, irregular tab stops.
  7.  
  8. ' $INCLUDE: 'TABMAN.BI'
  9. ' $INCLUDE: 'BITLIST.BI'                                        '**IRREG
  10.  
  11. DIM SHARED TabList AS INTEGER                                   '**IRREG
  12. DIM SHARED TabSize AS INTEGER                                   '**FIXED
  13. DIM SHARED TabStyle AS INTEGER                                  '**BOTH
  14.  
  15.  
  16. SUB ClrTab (TabStop AS INTEGER)
  17. ' ClrTab -      Clear the specified tab stop position.
  18.  
  19. IF TabStop = -1 THEN                                            '**IRREG
  20.   X% = blListOp(blClear, TabList, 0)                            '**IRREG
  21. ELSE                                                            '**IRREG
  22.   X% = blSetBit(TabList, TabStop - 1, 0)                        '**IRREG
  23. END IF                                                          '**IRREG
  24.  
  25. END SUB
  26.  
  27.  
  28. SUB DeTab (Hastabs$, Notabs$)
  29. ' DeTab -       Take the tabs out & replace w/correct  of spaces
  30.  
  31. Notabs$ = ""
  32. I% = 1: J% = 1
  33.  
  34. DO WHILE I% <= LEN(Hastabs$)
  35.   IF MID$(Hastabs$, I%, 1) <> CHR$(9) THEN
  36.     Notabs$ = Notabs$ + MID$(Hastabs$, I%, 1)
  37.     J% = J% + 1
  38.   ELSE
  39.     DO WHILE NOT IsTab(J%)
  40.       Notabs$ = Notabs$ + " "
  41.       J% = J% + 1
  42.     LOOP
  43.   END IF
  44.   I% = I% + 1
  45. LOOP
  46.  
  47. END SUB
  48.  
  49.  
  50. SUB EnTab (Notabs$, Hastabs$)
  51. ' EnTab - Subprogram to tabify a string
  52.  
  53. Hastabs$ = ""
  54. I% = 1
  55.  
  56. DO WHILE I% <= LEN(Notabs$)
  57.   IF MID$(Notabs$, I%, 1) <> " " THEN
  58.     Hastabs$ = Hastabs$ + MID$(Notabs$, I%, 1)
  59.     I% = I% + 1
  60.   ELSE
  61.     DO WHILE MID$(Notabs$, I%, 1) = " "
  62.       IF IsTab%(I% + 1) THEN
  63.         Hastabs$ = Hastabs$ + CHR$(9)
  64.         CS% = 0
  65.       ELSE
  66.         CS% = CS% + 1
  67.       END IF
  68.       I% = I% + 1
  69.     LOOP
  70.     IF CS% THEN
  71.       Hastabs$ = Hastabs$ + STRING$(CS%, " ")
  72.       CS% = 0
  73.     END IF
  74.   END IF
  75. LOOP
  76. END SUB
  77.  
  78.  
  79. SUB InitTabManager (Style AS INTEGER)
  80. ' InitTabManager - Initialize the tab manager package.
  81. '                  Specify TabStyle as 1 for fixed-interval tabs,
  82. '                  or specify 2 for irregular-intewrval tab stops.
  83.  
  84. TabStyle = Style                                                '**BOTH
  85. IF Style = 2 THEN                                               '**BOTH
  86.   TabList = blCreate(MAXTAB)                                    '**IRREG
  87. END IF                                                          '**BOTH
  88.  
  89. END SUB
  90.  
  91.  
  92. FUNCTION IsTab% (TabStop AS INTEGER)
  93. ' IsTab -       Function to see if there is a tab stop
  94. '               at the specified position. Returns TRUE if so,
  95. '               FALSE if no tab stop there.
  96.  
  97. IF TabStyle = 1 THEN                                            '**BOTH
  98.   IsTab% = ((TabStop - 1) MOD TabSize = 0)                      '**FIXED
  99. ELSE                                                            '**BOTH
  100.   IF TabStop > MAXTAB THEN                                      '**IRREG
  101.     IsTab% = TRUE                                               '**IRREG
  102.   ELSE                                                          '**IRREG
  103.     IsTab% = (blGetBit(TabList, TabStop - 1) <> 0)              '**IRREG
  104.   END IF                                                        '**IRREG
  105. END IF                                                          '**BOTH
  106.  
  107. END FUNCTION
  108.  
  109.  
  110. SUB SetTab (TabStop AS INTEGER)
  111. ' SetTab -      Set a tab stop at the specified position
  112.  
  113. IF TabStyle = 1 THEN                                            '**BOTH
  114.   TabSize = TabStop                                             '**FIXED
  115. ELSE                                                            '**BOTH
  116.   X% = blSetBit(TabList, TabStop - 1, 1)                        '**IRREG
  117. END IF                                                          '**BOTH
  118.  
  119. END SUB
  120.  
  121.